package com.qf.team2.netdisc.admin.service.impl;

import com.qf.team2.netdisc.admin.dao.AdminMapper;
import com.qf.team2.netdisc.admin.service.AdminManageService;
import com.qf.team2.netdisc.admin.service.AdminQueryService;
import com.qf.team2.netdisc.common.exception.BusinessException;
import com.qf.team2.netdisc.common.pojo.entity.Document;
import com.qf.team2.netdisc.common.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Simon_Wong
 * @since 2021/5/26 15:19
 */
@Service
public class AdminQueryServiceImpl implements AdminQueryService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public List<User> getAllUser() {
        List<User> dbUsers = adminMapper.selectAllUser();
        if (null==dbUsers||dbUsers.isEmpty()){
            throw new BusinessException("未知错误");
        }
        return dbUsers;
    }

    @Override
    public List<Document> getAllDocumentOfUser(Integer userId) {
        List<Document> documents = adminMapper.selectAllDocumentOfUser(userId);
        if (null==documents||documents.isEmpty()){
            throw new BusinessException("未知错误");
        }
        return documents;
    }
}
